<template>
	<view>
		<!-- 背景圖 -->
		<image class="backImage" src="http://139.159.229.212:8889/index/fujiajia/矩形111.png" mode="widthFix"></image>

		<view class="container">
			<!-- 用戶信息 -->
			<view class="user-info">
				<view class="user-info-left">
					<image v-if="userInfo.luohan==1" class="user-info-image" src="/static/luohan.png" mode="aspectFill">
					</image>
					<image v-else class="user-info-image" :src="userInfo.avatar || '/static/default_avatar.png'"
						mode=""></image>
					<view class="user-info-name" v-if="hasLogin">
						<view class="name">{{userInfo.nickname}}</view>
						<view class="info">
							<view class="uid">UID:{{userInfo.id}} <text class="user-copy" @tap.stop="copy">复制</text>
							</view>
							<view class="contribute">贡献值:{{userInfo.contribute}}</view>
							<view class="contribute" v-if="(userInfo.user_level==2 || userInfo.user_level==3)">
								流量券：{{userInfo.contribution}}</view>
						</view>
					</view>

					<view class="user-info-name" v-if="!hasLogin">
						<button class="login-btn" @tap="jumpTo('/pages/my/login', 'inside', false)"
							v-if="!hasLogin">点击登录</button>
					</view>
				</view>
				<view class="user-info-right" v-if="userInfo.user_level==3">
					<!-- https://app.yycjkb.cn/index/fujiajia/xunzhang.png -->
					<image class="medal" :src="userInfo.user_fee_level" mode=""></image>
					<view class="post">
						<image class="gradient" src="https://app.yycjkb.cn/index/fujiajia/jianbian.png" mode="">
						</image>
						<view>{{userInfo.post}}
						</view>
					</view>
				</view>
			</view>

			<!-- 錢包 -->
			<view class="money-bag">
				<image class="money-bag-image" src="http://139.159.229.212:8889/index/fujiajia/jianbianback.png"
					mode="">
				</image>
				<view class="money-bag-content">
					<view class="money-content-left">
						<view class="">
							<image src="#" mode=""></image>
							<text class="shopTitle">营收统计</text>
						</view>
						<view class="">
							<image src="#" mode=""></image>
							解锁所有权限
						</view>
					</view>
				</view>
			</view>

			<!-- 粉絲內容 -->
			<view class="small-assistant">
				<view class="revenue-content">
					<view class="revenue-title">
						营收明细
					</view>
					<view class="revenue">
						<view class="revenue-item" v-for="items in applyList">
							<view class="revenue-item-left">
								<view class="revenue-name" v-if="isActive!='entry'">
									提现到{{changeType(items)}}
								</view>
								<view class="revenue-name" v-else>
									{{items.memo?items.memo:'到账'}}
								</view>

								<view class="revenue-time">
									{{items.createtime|formDates}}
								</view>
							</view>
							<view class="revenue-item-right">+{{items.money}}元</view>
						</view>
					</view>
				</view>

				<!-- 返回按钮 -->
				<view class="back-button">
					返回
				</view>
			</view>
		</view>

		<!-- 底部tabbar -->
		<tabBar :selectIndex="selectIndex"></tabBar>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex';
	import banlance from '@/api/banlance';
	import user from '@/api/user';
	import tabBar from "@/newsPage/components/tabBar/index.vue"
	export default {
		components: {
			tabBar
		},
		data() {
			return {
				selectIndex: 2,
				money: 0,
				total_money: 0,
				non_withdrawable_balance: 0,
				withdrawable_balance: 0,
				standard: 0,
				isActive: 'entry',
				type: 'entry',
				more: 'more',
				all: 0.00,
				page: 1,
				applyList: [],
				orderList: [],
			};
		},
		filters: {
			formDates(times) {
				var times = new Date(times * 1000);
				var year = times.getFullYear(); //取得4位数的年份
				var month = times.getMonth() + 1; //取得日期中的月份，其中0表示1月，11表示12月
				var date = times.getDate(); //返回日期月份中的天数（1到31）
				var hour = times.getHours(); //返回日期中的小时数（0到23）
				var minute = times.getMinutes(); //返回日期中的分钟数（0到59）
				var second = times.getSeconds(); //返回日期中的秒数（0到59）
				return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
				// return new Date(parseInt(times) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
			}
		},
		onLoad() {
			this.getRecord(this.isActive);

		},
		onShow() {
			this.getUser()
		},
		computed: {
			...mapState(['config', 'hasLogin', 'userInfo']),
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),

			changeStatus() {
				return function(items) {
					switch (items.status) {
						case 1:
							return 'bg-green'
						case 2:
							return 'bg-red'
						default:
							return 'bg-black'
					}
				}
			},

			changeText() {
				return function(items) {
					switch (items.status) {
						case 1:
							return '待审核'
						case 2:
							return '已完成'
						default:
							return '已驳回'
					}
				}
			},
			changeType() {
				return function(items) {
					switch (items.types) {
						case 'wechat':
							return '微信'
						case 'weapp':
							return '微信'
						case 'alipay':
							return '支付宝'
					}
				}
			},
		},
		onPageScroll(e) {
			if (e.scrollTop > 600) { //当距离大于600时显示回到顶部按钮
				this.flag = true
			} else { //当距离小于600时隐藏回到顶部按钮
				this.flag = false
			}
		},
		onReachBottom() {
			if (this.more !== 'noMore') {
				this.more = 'loading'
				this.page++;
				this.getRecord(this.isActive);
			}
		},
		methods: {
			getUser() {

				user.index().then(res => {
					if (res.code === 1) {
						this.total_money = res.data.user.total_money;
						this.money = res.data.user.money
						this.non_withdrawable_balance = res.data.user.non_withdrawable_balance
						this.withdrawable_balance = res.data.user.withdrawable_balance
					}
				})

			},
			backTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 200
				});
			},
			backTop() {
				uni.pageScrollTo({
					scrollTop: 0,
					duration: 200
				});
			},
			async getRecord(type) {
				banlance.getRecord({
					page: this.page,
					tab: type
				}).then(res => {
					if (res.code == 1) {
						// this.applyList = res.data.list;
						this.applyList = this.applyList.concat(res.data.list);
						this.all = res.data.num;
						console.log(res);
					} else {
						console.log(res);
					}
					if (res.data.list.length <= 0) {
						this.more = 'noMore';
					} else {
						this.more = 'more';
					}
				});
			},
			goDeposit() {
				uni.navigateTo({
					url: './balance'
				})
			},
			goHistory() {
				uni.navigateTo({
					url: './history'
				})
			},
			toList() {
				uni.navigateTo({
					url: '/pages/my/balance/list'
				})
			},
			goTransfer() {
				uni.navigateTo({
					url: './transferMoney'
				})
			},
			switchLab(e) {
				// if(e=='apply'){
				// 	this.isActive = 'out';
				// }else{
				// 	this.isActive = 'entry';
				// }
				if (this.isActive == e) {
					return false;
				} else {
					this.isActive = e;
					this.applyList = [];
					this.page = 1;
					this.getRecord(this.isActive);
				}

			}
		}
	}
</script>

<style lang="less" scoped>
	.backImage {
		width: 100%;
		position: absolute;
		left: 0%;
	}

	.container {
		padding-top: 140rpx;
		padding-bottom: 20rpx;
		width: 690rpx;
		margin: auto;
		position: relative;

		.user-info {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.user-info-left {
				display: flex;

				.user-info-image {
					width: 137rpx;
					height: 137rpx;
					border-radius: 100rpx;
				}

				.user-info-name {
					display: flex;
					justify-content: space-between;
					flex-direction: column;
					padding: 10rpx 20rpx;

					.info {
						color: #666666;
						font-size: 24rpx;
						line-height: 140%;
					}
				}
			}

			.user-info-right {
				text-align: center;
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;

				.medal {
					width: 51rpx;
					height: 58rpx;
					margin-bottom: -5rpx;
				}

				.post {
					width: 98rpx;
					height: 38rpx;
					position: relative;
					color: #fff;
					padding: 10rpx 0;

					.gradient {
						width: 100%;
						height: 100%;
						position: absolute;
						left: 50%;
						transform: translate(-50%, 0);
					}

					view {
						z-index: 16;
						position: relative;
						line-height: 38rpx;
						transform: scale(0.8) !important;
						font-size: 16rpx;
					}
				}
			}
		}

		.money-bag {
			padding-top: 30rpx;

			.shopTitle {
				font-size: 30rpx;
				font-weight: bold;
			}

			.money-bag-image {
				width: 100%;
				height: 126rpx;
				position: absolute;
			}

			.money-bag-content {
				position: relative;
				padding: 0 30rpx;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 126rpx;

				.money-content-left {
					color: #FFF;

					view {
						display: flex;
						align-items: center;
						font-size: 24rpx;
						padding: 4rpx 0;

						image {
							vertical-align: middle;
							margin-right: 10rpx;
							width: 34rpx;
							height: 34rpx;
						}
					}
				}
			}
		}

		.small-assistant {
			width: 100%;
			background-color: #fff;
			border-radius: 24rpx;
			margin-top: 30rpx;
			padding: 20rpx 30rpx;
			min-height: 975rpx;
			position: relative;

			.revenue {
				padding: 20rpx 0;
			}

			.revenue-item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 20rpx 0;
				border-bottom: 2rpx solid #f6f6f6;

				.revenue-item-left {
					display: flex;
					justify-content: space-between;
					flex-direction: column;

					.revenue-name {
						padding-bottom: 10rpx;
					}

					.revenue-time {
						color: #999999;
						font-size: 24rpx;
					}
				}

				.revenue-item-right {
					color: #f76e00;
				}
			}

			.back-button {
				width: 230rpx;
				height: 76rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				margin: 40rpx auto;
				margin-top: 50rpx;
				background: linear-gradient(90deg, rgba(254, 176, 122, 1) 35%, rgba(242, 171, 235, 1) 100%);
				border-radius: 20rpx;
				color: #fff;
				position: relative;
				bottom: 2%;
				// left: 50%;
				// transform: translateX(-50%);
			}
		}
	}
</style>